package com.gx.smart.building.ui.swap.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemSwapRecordLayoutBinding;
import com.huishi.gx.ib.grpc.lib.ib.admin.schedule.v1.RecordDto;

/**
 * @author xiaosy
 * @create 2020/5/8
 * @Describe 维修详情
 **/
public class SwapRecordAdapter extends BaseAdapter<RecordDto, SwapRecordAdapter.ViewHolder> {
    public SwapRecordAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_swap_record_layout;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemSwapRecordLayoutBinding binding = ItemSwapRecordLayoutBinding.inflate(LayoutInflater.from(mContext),
                (ViewGroup) view, false);
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, RecordDto item, int position) {
        //交接单状态 1未签收 2已签收 预留（3提前签收 4超时签收）
        if (item.getStatus() == 2) {
            holder.binding.status.setText("已完成");
            holder.binding.status.setTextColor(mContext.getResources().getColor(R.color.font_color_style_24));
            holder.binding.status.setBackgroundResource(R.drawable.shape_status_green_text_view_background);
            String time = TimeUtils.millis2String(item.getCheckTime(), "yyyy-MM-dd HH:mm");
            holder.binding.floatTimeEnd.setText("完成时间: " + time);
        } else {
            holder.binding.status.setText("未签收");
            holder.binding.status.setTextColor(mContext.getResources().getColor(R.color.font_color_style_eleven));
            holder.binding.status.setBackgroundResource(R.drawable.shape_status_text_view_background);
            holder.binding.floatTimeEnd.setText("完成时间: 未完成");
        }
        holder.binding.scheduleName.setText("交接班时: " + item.getScheduleName());
        //App专用 1我的交班 2我的接班
        if (item.getRecordType() == 1) {
            holder.binding.type.setText("我的交班");
            //接班人
            if (TextUtils.isEmpty(item.getOverPerson())) {
                holder.binding.shiftOverPerson.setText("接班人: 无");
            } else {
                holder.binding.shiftOverPerson.setText("接班人: " + item.getOverPerson());
            }

        } else {
            holder.binding.type.setText("我的接班");
            //交班人
            if (TextUtils.isEmpty(item.getShiftPerson())) {
                holder.binding.shiftOverPerson.setText("交班人: 无");
            } else {
                holder.binding.shiftOverPerson.setText("交班人: " + item.getShiftPerson());
            }

        }


    }

    protected static class ViewHolder extends RecyclerView.ViewHolder {
        private final ItemSwapRecordLayoutBinding binding;

        public ViewHolder(ItemSwapRecordLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }

}
